import { watch } from 'vue'
import { useTitle as usePageTitle } from '@vueuse/core'
import { useRoute } from 'vue-router'

export function useTitle() {
  const currentRoute = useRoute()
  const pageTitle = usePageTitle()

  watch(
    () => currentRoute.path,
    () => {
      const routeTitle = currentRoute.meta.title
      const defaultTitle = '深圳市分行智能统计报表集成管理平台'
      pageTitle.value = routeTitle ? `${routeTitle} - ${defaultTitle}` : `${defaultTitle}`
    },
    { immediate: true }
  )
}
